<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: D:/Projects/MiXiM/extsrc/mixim/src/inet_stub/mobility/models/TraCIMobility.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00381.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">TraCIMobility.h</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//</span>
<a name="l00002"></a>00002 <span class="comment">// Copyright (C) 2006-2012 Christoph Sommer &lt;christoph.sommer@uibk.ac.at&gt;</span>
<a name="l00003"></a>00003 <span class="comment">//</span>
<a name="l00004"></a>00004 <span class="comment">// Documentation for these modules is at http://veins.car2x.org/</span>
<a name="l00005"></a>00005 <span class="comment">//</span>
<a name="l00006"></a>00006 <span class="comment">// This program is free software; you can redistribute it and/or modify</span>
<a name="l00007"></a>00007 <span class="comment">// it under the terms of the GNU General Public License as published by</span>
<a name="l00008"></a>00008 <span class="comment">// the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00009"></a>00009 <span class="comment">// (at your option) any later version.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// This program is distributed in the hope that it will be useful,</span>
<a name="l00012"></a>00012 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00013"></a>00013 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00014"></a>00014 <span class="comment">// GNU General Public License for more details.</span>
<a name="l00015"></a>00015 <span class="comment">//</span>
<a name="l00016"></a>00016 <span class="comment">// You should have received a copy of the GNU General Public License</span>
<a name="l00017"></a>00017 <span class="comment">// along with this program; if not, write to the Free Software</span>
<a name="l00018"></a>00018 <span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span>
<a name="l00019"></a>00019 <span class="comment">//</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 <span class="preprocessor">#ifndef MOBILITY_TRACI_TRACIMOBILITY_H</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#define MOBILITY_TRACI_TRACIMOBILITY_H</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">#ifdef WITH_TRACI</span>
<a name="l00024"></a>00024 <span class="preprocessor"></span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;fstream&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;list&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;stdexcept&gt;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;omnetpp.h&gt;</span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="preprocessor">#include &quot;MobilityBase.h&quot;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;ModuleAccess.h&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;world/traci/TraCIScenarioManager.h&quot;</span>
<a name="l00035"></a>00035 
<a name="l00052"></a>00052 <span class="keyword">class </span>INET_API TraCIMobility : <span class="keyword">public</span> <a class="code" href="a00145.html" title="Abstract base class for mobility modules.">MobilityBase</a>
<a name="l00053"></a>00053 {
<a name="l00054"></a>00054     <span class="keyword">public</span>:
<a name="l00055"></a>00055         <span class="keyword">class </span>Statistics {
<a name="l00056"></a>00056             <span class="keyword">public</span>:
<a name="l00057"></a>00057                 <span class="keywordtype">double</span> firstRoadNumber; 
<a name="l00058"></a>00058                 simtime_t startTime; 
<a name="l00059"></a>00059                 simtime_t totalTime; 
<a name="l00060"></a>00060                 simtime_t stopTime; 
<a name="l00061"></a>00061                 <span class="keywordtype">double</span> minSpeed; 
<a name="l00062"></a>00062                 <span class="keywordtype">double</span> maxSpeed; 
<a name="l00063"></a>00063                 <span class="keywordtype">double</span> totalDistance; 
<a name="l00064"></a>00064                 <span class="keywordtype">double</span> totalCO2Emission; 
<a name="l00066"></a>00066                 <span class="keywordtype">void</span> initialize();
<a name="l00067"></a>00067                 <span class="keywordtype">void</span> watch(cSimpleModule&amp; module);
<a name="l00068"></a>00068                 <span class="keywordtype">void</span> recordScalars(cSimpleModule&amp; module);
<a name="l00069"></a>00069         };
<a name="l00070"></a>00070 
<a name="l00071"></a>00071         TraCIMobility() : <a class="code" href="a00145.html" title="Abstract base class for mobility modules.">MobilityBase</a>(), isPreInitialized(false) {}
<a name="l00072"></a>00072         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00145.html#a4c79fdde6758f5cb3b879d8a712911c9" title="Initializes mobility model parameters in 4 stages.">initialize</a>(<span class="keywordtype">int</span> stage);
<a name="l00073"></a>00073         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00145.html#ae4fcd350112d303b0d58f39e56b07c6b" title="Initializes the position from the display string or from module parameters.">initializePosition</a>();
<a name="l00074"></a>00074         <span class="keyword">virtual</span> <span class="keywordtype">void</span> finish();
<a name="l00075"></a>00075         <span class="keyword">virtual</span> <a class="code" href="a00065.html" title="Class for storing 3D coordinates.">Coord</a> <a class="code" href="a00101.html#abbf2edff2f9570cada67952fc1eb886d" title="Returns the current position at the current simulation time.">getCurrentPosition</a>() {
<a name="l00076"></a>00076             <span class="keywordflow">return</span> getPosition();
<a name="l00077"></a>00077         }
<a name="l00078"></a>00078         <span class="keyword">virtual</span> <a class="code" href="a00065.html" title="Class for storing 3D coordinates.">Coord</a> <a class="code" href="a00101.html#afb4a58c38ef32d3f0e6e7ec37ff4fc1c" title="Returns the current speed at the current simulation time.">getCurrentSpeed</a>() {
<a name="l00079"></a>00079             <a class="code" href="a00065.html" title="Class for storing 3D coordinates.">Coord</a> v = <a class="code" href="a00065.html" title="Class for storing 3D coordinates.">Coord</a>(cos(getAngleRad()), -sin(getAngleRad()));
<a name="l00080"></a>00080             <span class="keywordflow">return</span> v * getSpeed();
<a name="l00081"></a>00081         }
<a name="l00082"></a>00082 
<a name="l00083"></a>00083         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00145.html#a42e16e37a9670e4faa781e30540094cb" title="Called upon arrival of a self messages, subclasses must override.">handleSelfMessage</a>(cMessage *msg);
<a name="l00084"></a>00084         <span class="keyword">virtual</span> <span class="keywordtype">void</span> preInitialize(std::string external_id, <span class="keyword">const</span> <a class="code" href="a00065.html" title="Class for storing 3D coordinates.">Coord</a>&amp; position, std::string road_id = <span class="stringliteral">&quot;&quot;</span>, <span class="keywordtype">double</span> speed = -1, <span class="keywordtype">double</span> angle = -1);
<a name="l00085"></a>00085         <span class="keyword">virtual</span> <span class="keywordtype">void</span> nextPosition(<span class="keyword">const</span> <a class="code" href="a00065.html" title="Class for storing 3D coordinates.">Coord</a>&amp; position, std::string road_id = <span class="stringliteral">&quot;&quot;</span>, <span class="keywordtype">double</span> speed = -1, <span class="keywordtype">double</span> angle = -1, TraCIScenarioManager::VehicleSignal signals = TraCIScenarioManager::VEH_SIGNAL_UNDEF);
<a name="l00086"></a>00086         <span class="keyword">virtual</span> <span class="keywordtype">void</span> move();
<a name="l00087"></a>00087         <span class="keyword">virtual</span> <span class="keywordtype">void</span> updateDisplayString();
<a name="l00088"></a>00088         <span class="keyword">virtual</span> <span class="keywordtype">void</span> setExternalId(std::string external_id) {
<a name="l00089"></a>00089             this-&gt;external_id = external_id;
<a name="l00090"></a>00090         }
<a name="l00091"></a>00091         <span class="keyword">virtual</span> std::string getExternalId()<span class="keyword"> const </span>{
<a name="l00092"></a>00092             <span class="keywordflow">if</span> (external_id == <span class="stringliteral">&quot;&quot;</span>) <span class="keywordflow">throw</span> cRuntimeError(<span class="stringliteral">&quot;TraCIMobility::getExternalId called with no external_id set yet&quot;</span>);
<a name="l00093"></a>00093             <span class="keywordflow">return</span> external_id;
<a name="l00094"></a>00094         }
<a name="l00095"></a>00095         <span class="keyword">virtual</span> <a class="code" href="a00065.html" title="Class for storing 3D coordinates.">Coord</a> getPosition()<span class="keyword"> const </span>{
<a name="l00096"></a>00096             <span class="keywordflow">return</span> <a class="code" href="a00145.html#a82ae637969433a492154b26039b84038" title="The last position that was reported.">lastPosition</a>;
<a name="l00097"></a>00097         }
<a name="l00098"></a>00098         <span class="keyword">virtual</span> std::string getRoadId()<span class="keyword"> const </span>{
<a name="l00099"></a>00099             <span class="keywordflow">if</span> (road_id == <span class="stringliteral">&quot;&quot;</span>) <span class="keywordflow">throw</span> cRuntimeError(<span class="stringliteral">&quot;TraCIMobility::getRoadId called with no road_id set yet&quot;</span>);
<a name="l00100"></a>00100             <span class="keywordflow">return</span> road_id;
<a name="l00101"></a>00101         }
<a name="l00102"></a>00102         <span class="keyword">virtual</span> <span class="keywordtype">double</span> getSpeed()<span class="keyword"> const </span>{
<a name="l00103"></a>00103             <span class="keywordflow">if</span> (speed == -1) <span class="keywordflow">throw</span> cRuntimeError(<span class="stringliteral">&quot;TraCIMobility::getSpeed called with no speed set yet&quot;</span>);
<a name="l00104"></a>00104             <span class="keywordflow">return</span> speed;
<a name="l00105"></a>00105         }
<a name="l00106"></a>00106         <span class="keyword">virtual</span> TraCIScenarioManager::VehicleSignal getSignals()<span class="keyword"> const </span>{
<a name="l00107"></a>00107             <span class="keywordflow">if</span> (signals == -1) <span class="keywordflow">throw</span> cRuntimeError(<span class="stringliteral">&quot;TraCIMobility::getSignals called with no signals set yet&quot;</span>);
<a name="l00108"></a>00108             <span class="keywordflow">return</span> signals;
<a name="l00109"></a>00109         }
<a name="l00113"></a>00113         <span class="keyword">virtual</span> <span class="keywordtype">double</span> getAngleRad()<span class="keyword"> const </span>{
<a name="l00114"></a>00114             <span class="keywordflow">if</span> (angle == M_PI) <span class="keywordflow">throw</span> cRuntimeError(<span class="stringliteral">&quot;TraCIMobility::getAngleRad called with no angle set yet&quot;</span>);
<a name="l00115"></a>00115             <span class="keywordflow">return</span> angle;
<a name="l00116"></a>00116         }
<a name="l00117"></a>00117         <span class="keyword">virtual</span> TraCIScenarioManager* getManager()<span class="keyword"> const </span>{
<a name="l00118"></a>00118             <span class="keywordflow">if</span> (!manager) manager = TraCIScenarioManagerAccess().get();
<a name="l00119"></a>00119             <span class="keywordflow">return</span> manager;
<a name="l00120"></a>00120         }
<a name="l00121"></a>00121         <span class="keywordtype">void</span> commandSetSpeedMode(int32_t bitset) {
<a name="l00122"></a>00122             getManager()-&gt;commandSetSpeedMode(getExternalId(), bitset);
<a name="l00123"></a>00123         }
<a name="l00124"></a>00124         <span class="keywordtype">void</span> commandSetSpeed(<span class="keywordtype">double</span> speed) {
<a name="l00125"></a>00125             getManager()-&gt;commandSetSpeed(getExternalId(), speed);
<a name="l00126"></a>00126         }
<a name="l00127"></a>00127         <span class="keywordtype">void</span> commandChangeRoute(std::string roadId, <span class="keywordtype">double</span> travelTime) {
<a name="l00128"></a>00128             getManager()-&gt;commandChangeRoute(getExternalId(), roadId, travelTime);
<a name="l00129"></a>00129         }
<a name="l00130"></a>00130 
<a name="l00131"></a>00131         <span class="keywordtype">void</span> commandNewRoute(std::string roadId) {
<a name="l00132"></a>00132             getManager()-&gt;commandNewRoute(getExternalId(), roadId);
<a name="l00133"></a>00133         }
<a name="l00134"></a>00134         <span class="keywordtype">void</span> commandParkVehicle() {
<a name="l00135"></a>00135             getManager()-&gt;commandSetVehicleParking(getExternalId());
<a name="l00136"></a>00136         }
<a name="l00137"></a>00137 
<a name="l00138"></a>00138         <span class="keywordtype">double</span> commandDistanceRequest(<a class="code" href="a00065.html" title="Class for storing 3D coordinates.">Coord</a> position1, <a class="code" href="a00065.html" title="Class for storing 3D coordinates.">Coord</a> position2, <span class="keywordtype">bool</span> returnDrivingDistance) {
<a name="l00139"></a>00139             <span class="keywordflow">return</span> getManager()-&gt;commandDistanceRequest(position1, position2, returnDrivingDistance);
<a name="l00140"></a>00140         }
<a name="l00141"></a>00141         <span class="keywordtype">void</span> commandStopNode(std::string roadId, <span class="keywordtype">double</span> pos, uint8_t laneid, <span class="keywordtype">double</span> radius, <span class="keywordtype">double</span> waittime) {
<a name="l00142"></a>00142             <span class="keywordflow">return</span> getManager()-&gt;commandStopNode(getExternalId(), roadId, pos, laneid, radius, waittime);
<a name="l00143"></a>00143         }
<a name="l00144"></a>00144         std::list&lt;std::string&gt; commandGetPolygonIds() {
<a name="l00145"></a>00145             <span class="keywordflow">return</span> getManager()-&gt;commandGetPolygonIds();
<a name="l00146"></a>00146         }
<a name="l00147"></a>00147         std::string commandGetPolygonTypeId(std::string polyId) {
<a name="l00148"></a>00148             <span class="keywordflow">return</span> getManager()-&gt;commandGetPolygonTypeId(polyId);
<a name="l00149"></a>00149         }
<a name="l00150"></a>00150         std::list&lt;Coord&gt; commandGetPolygonShape(std::string polyId) {
<a name="l00151"></a>00151             <span class="keywordflow">return</span> getManager()-&gt;commandGetPolygonShape(polyId);
<a name="l00152"></a>00152         }
<a name="l00153"></a>00153         <span class="keywordtype">void</span> commandSetPolygonShape(std::string polyId, std::list&lt;Coord&gt; points) {
<a name="l00154"></a>00154             getManager()-&gt;commandSetPolygonShape(polyId, points);
<a name="l00155"></a>00155         }
<a name="l00156"></a>00156         <span class="keywordtype">bool</span> commandAddVehicle(std::string vehicleId, std::string vehicleTypeId, std::string routeId, std::string laneId, <span class="keywordtype">double</span> emitPosition, <span class="keywordtype">double</span> emitSpeed) {
<a name="l00157"></a>00157             <span class="keywordflow">return</span> getManager()-&gt;commandAddVehicle(vehicleId, vehicleTypeId, routeId, laneId, emitPosition, emitSpeed);
<a name="l00158"></a>00158         }
<a name="l00159"></a>00159 
<a name="l00160"></a>00160     <span class="keyword">protected</span>:
<a name="l00161"></a>00161         <span class="keywordtype">bool</span> <a class="code" href="a00031.html#a6ad967ecb9d1507f3efea5a11f89eae7" title="Debug switch for all other modules.">debug</a>; 
<a name="l00162"></a>00162         <span class="keywordtype">int</span> accidentCount; 
<a name="l00164"></a>00164         cOutVector currentPosXVec; 
<a name="l00165"></a>00165         cOutVector currentPosYVec; 
<a name="l00166"></a>00166         cOutVector currentSpeedVec; 
<a name="l00167"></a>00167         cOutVector currentAccelerationVec; 
<a name="l00168"></a>00168         cOutVector currentCO2EmissionVec; 
<a name="l00170"></a>00170         Statistics statistics; 
<a name="l00172"></a>00172         <span class="keywordtype">bool</span> isPreInitialized; 
<a name="l00174"></a>00174         std::string external_id; 
<a name="l00176"></a>00176         simtime_t lastUpdate; 
<a name="l00177"></a>00177         <a class="code" href="a00065.html" title="Class for storing 3D coordinates.">Coord</a> nextPos; 
<a name="l00178"></a>00178         std::string road_id; 
<a name="l00179"></a>00179         <span class="keywordtype">double</span> speed; 
<a name="l00180"></a>00180         <span class="keywordtype">double</span> angle; 
<a name="l00181"></a>00181         TraCIScenarioManager::VehicleSignal signals; 
<a name="l00183"></a>00183         cMessage* startAccidentMsg;
<a name="l00184"></a>00184         cMessage* stopAccidentMsg;
<a name="l00185"></a>00185         <span class="keyword">mutable</span> TraCIScenarioManager* manager;
<a name="l00186"></a>00186         <span class="keywordtype">double</span> last_speed;
<a name="l00187"></a>00187 
<a name="l00188"></a>00188         <span class="keyword">virtual</span> <span class="keywordtype">void</span> fixIfHostGetsOutside(); 
<a name="l00196"></a>00196         <span class="keywordtype">double</span> calculateCO2emission(<span class="keywordtype">double</span> v, <span class="keywordtype">double</span> a) <span class="keyword">const</span>;
<a name="l00197"></a>00197 };
<a name="l00198"></a>00198 
<a name="l00199"></a>00199 <span class="keyword">class </span>TraCIMobilityAccess : <span class="keyword">public</span> <a class="code" href="a00146.html">ModuleAccess</a>&lt;TraCIMobility&gt;
<a name="l00200"></a>00200 {
<a name="l00201"></a>00201     <span class="keyword">public</span>:
<a name="l00202"></a>00202         TraCIMobilityAccess() : <a class="code" href="a00146.html">ModuleAccess</a>&lt;TraCIMobility&gt;(<span class="stringliteral">&quot;mobility&quot;</span>) {};
<a name="l00203"></a>00203 };
<a name="l00204"></a>00204 
<a name="l00205"></a>00205 
<a name="l00206"></a>00206 <span class="preprocessor">#endif</span>
<a name="l00207"></a>00207 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00208"></a>00208 <span class="preprocessor"></span>
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>TraCIMobility.h</b>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:30 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
